/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.comboBox;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.ImageIcon;

import org.jxSwing.component.comboBox.cellRenderer.IconListRenderer;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.comboBox
 * @date 05/02/2014 - 22:38:23
 */
public class ImageComboBox extends ComboBox<ImageIcon> {
	
	private static final long serialVersionUID = -3554854222509490107L;
	
	/**
	 * 
	 */
	public ImageComboBox() {
	
		super();
		
		initGUI();
	}
	
	/**
	 * @param bufferedImages
	 */
	public ImageComboBox(final BufferedImage[] bufferedImages) {
	
		this((Image[])bufferedImages);
	}
	
	/**
	 * @param aModel
	 */
	public ImageComboBox(final ComboBoxModel<ImageIcon> aModel) {
	
		super(aModel);
		
		initGUI();
	}
	
	/**
	 * @param images
	 */
	public ImageComboBox(final Image[] images) {
	
		super(toImageIconList(images));
		
		initGUI();
	}
	
	/**
	 * @param items
	 */
	public ImageComboBox(final ImageIcon[] items) {
	
		super(items);
		
		initGUI();
	}
	
	/**
	 * @param imageIcons
	 */
	public ImageComboBox(final List<ImageIcon> imageIcons) {
	
		super(imageIcons);
		
		initGUI();
	}
	
	/**
	 * @param items
	 */
	public ImageComboBox(final Vector<ImageIcon> items) {
	
		super(items);
		
		initGUI();
	}
	
	/**
	 * 
	 */
	private void initGUI() {
	
		setRenderer(new IconListRenderer());
	}
	
	/**
	 * @param images
	 * @return imageIcons
	 */
	private static List<ImageIcon> toImageIconList(final Image[] images) {
	
		final List<ImageIcon> imageIcons = new ArrayList<>();
		
		//
		for(final Image image : images) {
			
			imageIcons.add(new ImageIcon(image));
		}
		
		return imageIcons;
	}
}
